
  function Encrypt(word){
     var key = CryptoJS.enc.Utf8.parse("abcdefgabcdefghi"); 

     var srcs = CryptoJS.enc.Utf8.parse(word);
     var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
         return encrypted.toString();
  }
  function Decrypt(word){
     var key = CryptoJS.enc.Utf8.parse("abcdefgabcdefghi"); 

     var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
     return CryptoJS.enc.Utf8.stringify(decrypt).toString();
  }


function dologin() {

  $.ajax({
    type: "get",
    contentType: "application/json",
    headers: {
      'userToken': localStorage.userToken
    },
    url: URL_all+'public/rsakey',

    success: function(data) {
      var username = $("#username").val();
      var password = $("#password").val();
      var code = $("#code").val();

      if(username=='' ){
        alert('用户名不能为空')
        return false;
      }
      if(code=='' ){
        alert('请输入验证码')
        return false;
      }
      if(password=='' ){
        alert('密码不能为空')
        return false;
      }
      
      else{
      var encrypt = new JSEncrypt();
      encrypt.setPublicKey(data.dataResultObj.RsaKey);
      console.log("json.thePubKey:" + data.dataResultObj.RsaKey);
      username = MD5(MD5(username));
      password = MD5(MD5(password));
      username = encrypt.encrypt(username);
      password = encrypt.encrypt(password);

      // console.log(username);
      // console.log(password);

      
      $.ajax({
        type: "post",
        contentType: "application/json",
        headers: {
          'AdminToken': localStorage.AdminToken
        },
        url: URL_all+'system/admin/login',
        data: "{'username':'" + username + "','password':'" + password + "','IdentifyCode':'" + code + "'}",
        success: function(data) {
          localStorage.AdminToken = data.dataResultObj.adminToken
          console.log(localStorage.AdminToken)
          console.log(data)
          // if(username==username&&password==password){
            alert("登录成功");
          // }
      
        }
      });
    }
    }
  });
}
/*验证码*/
  $("#verifyimg").click(function() {
    ajaxcode()
  })
 $(function() {
    ajaxcode()
  }) 
  function ajaxcode() {
    $.ajax({
      type: "get",
      contentType: "application/json",
      headers: {
        'AdminToken': localStorage.AdminToken
      },
      url: URL_all+'public/system/getverificode',
      data: new Date().getTime(),
      success: function(data) {
        localStorage.AdminToken = data.dataResultObj.LoginToken
        $("#verifyimg").attr("src", "data:image/png;base64," + data.dataResultObj.CodeImg);
      }
    });
  }